package com.bnzj.core.persistence.query;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author barry
 * @date 2019-10-06
 */
public abstract class AbstractExpression implements IExpression {
    
    private final boolean negated;//是否是not操作
    
    public AbstractExpression() {
        this(false);
    }
    
    public AbstractExpression(boolean negated) {
        this.negated = negated;
    }

    /* (non-Javadoc)
     * @see com.bnzj.core.persistence.query.IExpression#and(com.bnzj.core.persistence.query.IExpression[])
     */
    @Override
    public IExpression and(IExpression... expressions) {
        List<IExpression> list = new ArrayList<IExpression>(Arrays.asList(expressions));
        list.add(0, this);
        return new LogicExpression(BooleanOperator.and, list);
    }

    /* (non-Javadoc)
     * @see com.bnzj.core.persistence.query.IExpression#or(com.bnzj.core.persistence.query.IExpression[])
     */
    @Override
    public IExpression or(IExpression... expressions) {
        List<IExpression> list = new ArrayList<IExpression>(Arrays.asList(expressions));
        list.add(0, this);
        return new LogicExpression(BooleanOperator.or, list);
    }

    /* (non-Javadoc)
     * @see com.bnzj.core.persistence.query.IExpression#buildSQL(java.util.Map)
     */
    @Override
    public String buildSQL(Map<String, Object> paramsMap) {
        return "";
    }

    @Override
    public boolean isNegated() {
         return negated;
    }
}
